/** @jsxImportSource @emotion/react */
import * as React from "react";
import {
   CCell, Table, TableBody, TableRow, Text, TableHead,
} from "customize-easy-ui-component";
import { DirectLink, } from "../../../routing/Link";
import {getInstrument2xCol, } from "../../common/helper";
import {input使用情况} from "./orcBase";
import {useJudgmentTable} from "../../hook/useJudgment";
import {render层站门数} from "../../common/render";
import {楼盘地点性质} from "../../elevator/RoomLessJJ/orcBase";

/*正式报告用
* */
export const config报告设备 = [
  [['设备名称', '_$设备名称'], ['使用登记编号', '_$使用证号'], ],
  [['使用单位名称', '_$使用单位'], ['楼盘名称', '_$楼盘'],],
  [['单位地址', '_$使用单位地址'],  ],
  [['楼盘地址', '_$楼盘地址'] ],
  [['分支机构名称', '_$分支机构'], ['分支机构地址', '_$分支机构地址'] ],
  [['联系人','_$设备联系人'],['联系电话','_$设备联系手机'] ],
  [['安装地点','_$设备使用地点'], ['使用单位编号', '_$单位内部编号'], ],
  [['设备号','_$eqpcod'],['制造日期','_$制造日期']],
  [['产品型号', '_$型号'], ['产品编号', '_$出厂编号'] ],
  [['额定载重量','_$额定载荷','kg'], ['额定速度', '_$运行速度','m/s'] ],
  [['层站门数', '_$电梯层数',render层站门数], ['制动器型式', '制器型',] ],
  [['制造单位名称', '_$制造单位'], ['维保单位名称', '_$维保单位'] ],
  [['使用场所', {n: '楼地性质', t: 'l', l: 楼盘地点性质}], ['上行超速保护装置型号', '_$上行保护型号'],],
  [['轿厢意外移动保护装置型号', '_$意外保护型号'], ['是否非金属反绳轮',{n:'非金反绳',t:'b'}] ],
  [['设备使用情况', '限超过', input使用情况] ],
];

export const 报告检测仪器 = ({orc, repId, verId, rep}: { orc: any, repId: string, verId: string, rep: any }
) => {
  const instrumentTable = React.useMemo(() => getInstrument2xCol(orc.仪器表), [orc.仪器表]);
  return <React.Fragment>
    <div css={{"@media print": {paddingBottom: '4rem', pageBreakInside: 'avoid'}}}>
      <Text variant="h4" css={{marginTop: '1rem',
      }}>三、主要检测仪器</Text>
    </div>
    <Table fixed={ ["4.2%", "33%", "15%", "4.2%", "%", "15%"] }
                  css={{borderCollapse: 'collapse', "@media print": {marginTop: '-4rem'}}} tight miniw={800}>
        <TableBody>
          <DirectLink href={`/report/${rep?.modeltype}/ver/${verId}/${repId}/Instrument`}>
            <TableRow>
              <CCell>序号</CCell>
              <CCell>仪器名称</CCell>
              <CCell>仪器编号</CCell>
              <CCell>序号</CCell>
              <CCell>仪器名称</CCell>
              <CCell>仪器编号</CCell>
            </TableRow>
            {instrumentTable.map((o, i) => {
              return (
                  <TableRow key={i}>
                    <CCell>{o.s1}</CCell>
                    <CCell>{o.name1}</CCell>
                    <CCell css={{wordBreak: 'break-all'}}>{o.no1}</CCell>
                    <CCell>{o.s2}</CCell>
                    <CCell>{o.name2}</CCell>
                    <CCell css={{wordBreak: 'break-all'}}>{o.no2}</CCell>
                  </TableRow>
              );
            })}
          </DirectLink>
        </TableBody>
      </Table>
  </React.Fragment>;
};

export const 测量结果记录= ({ orc, rep,label,config,fixed=["2.6%", "5%", "3%", "6%", "%", "23%", "5%", "9.1%", "7.1%", "5%"],tag='Measure',children}
                                : { orc: any, rep: any,label:string,config:any,fixed?:string[],tag?:string,children?: React.ReactNode}
) => {
  const renderMeasure=useJudgmentTable({rep,orc, config});
  return <>
    <Text variant="h4" css={{marginTop: '1rem',
    }}>{label}</Text>
    <Table id={tag} fixed={fixed}  css={ {borderCollapse: 'collapse' } } tight  miniw={800}>
      <TableHead>
        <TableRow>
          <CCell><Text css={{fontSize:'0.8rem'}}>序号</Text></CCell><CCell><Text css={{fontSize:'0.7rem'}}>项目编号</Text></CCell>
          <CCell colSpan={3}>检验内容与要求</CCell><CCell>检测项目</CCell><CCell>单位</CCell>
          <CCell>观测数据</CCell><CCell>测量结果</CCell><CCell><Text css={{fontSize:'0.8rem'}}>结果判定</Text></CCell>
        </TableRow>
      </TableHead>
      <TableBody>
        <DirectLink  href={`/report/${rep?.modeltype}/ver/${rep?.modelversion}/${rep?.id}/Measure?original=1#Measure`}>
          {renderMeasure}
        </DirectLink>
      </TableBody>
    </Table>
    {children? children :
        <Text css={{fontSize:'0.8rem'}}>
          注：本表所列项目无测量时，观测数据和测量结果可不填，但结果判定应填写，对不适用项填“/”。
        </Text>
    }
  </>;
};

/*特殊布局：<p>段落区域也会自动协调的？
      <Text css={{
        textIndent: '2rem',
        display: 'flex',
      }}>
        <p> 1、111存在 个不符合项目，这些项目不符合《；</p>
        2、222存改（成前，维保单位应当加效的安全监护措施；<br/>
        3、333存在的发或标准见表3）。
      </Text>
* */
